//
//  YZEPatientHeadView.m
//  yilutongxing
//
//  Created by 赵继申 on 17/3/21.
//  Copyright © 2017年 YZE. All rights reserved.
//

#import "YZEPatientHeadView.h"
#import "YZEPatientHeadTableViewCell2.h"
#import "YZEPatientHeadTableViewCell3.h"
#import "DailyTableViewCell.h"
#import "UITableView+EmptyData.h"

//cell内容模型
@implementation YZEPatientHeadViewCellModel

@end


@interface YZEPatientHeadView()
@property(nonatomic,assign) BOOL is_medicine_plan;
@end

@implementation YZEPatientHeadView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        _label_title = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, GetViewWidthFlaot(self), 30)];
        _label_title.textColor = [UIColor whiteColor];
        _label_title.backgroundColor = [UIColor clearColor];//[UIColor colorWithRed:71/255.0 green:140/255.0 blue:236/255.0 alpha:1.0];
        
        _label_title.textAlignment = NSTextAlignmentCenter;
        _label_title.font = [UIFont systemFontOfSize:15];
        [self addSubview:_label_title];
        
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 30, GetViewWidthFlaot(self), GetViewHeightFlaot(self)-40) style:UITableViewStyleGrouped];
        if (@available(iOS 11.0, *)) {
            _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        }
        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.backgroundColor = [UIColor clearColor];//[UIColor colorWithRed:71/255.0 green:140/255.0 blue:236/255.0 alpha:1.0];

        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.userInteractionEnabled = YES;
        
        _is_medicine_plan = NO;
        
        UINib *nib = [UINib nibWithNibName:@"DailyTableViewCell" bundle:nil];
        [_tableView registerNib:nib forCellReuseIdentifier:@"DailyTableViewCell"];
        nib = [UINib nibWithNibName:@"YZEPatientHeadTableViewCell2" bundle:nil];
        [_tableView registerNib:nib forCellReuseIdentifier:@"YZEPatientHeadTableViewCell2"];
        nib = [UINib nibWithNibName:@"YZEPatientHeadTableViewCell3" bundle:nil];
        [_tableView registerNib:nib forCellReuseIdentifier:@"YZEPatientHeadTableViewCell3"];
        
        [self addSubview:_tableView];
    }
    return self;
}

- (void)setIsMedicinePlan:(BOOL)flag{
    self.is_medicine_plan = flag;
}

#pragma mark - TableView Datasrouce & Delegate
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    [tableView tableViewDisplayMsgWithClearBg:[NSString stringWithFormat:@"暂无%@", self.label_title.text] msgcolor:COLOR(255,255,255) ifNecessaryForRowCount:self.dataArr.count];
    return self.dataArr.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (self.row_height) {
        return [self.row_height floatValue];
    }
    if (self.is_medicine_plan) {
        return 60;
    }
    return 28;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    YZEPatientHeadViewCellModel *model = self.dataArr[indexPath.row];
    if (model.cell_type==1) {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"NormalCell"];
        if (!cell) {
            cell = [[UITableViewCell alloc]initWithFrame:CGRectMake(0, 0, tableView.width, 28)];
        }
        cell.backgroundColor=[UIColor clearColor];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        
        UILabel *l = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, cell.width, cell.height)];
        l.textAlignment = NSTextAlignmentCenter;
        l.textColor = WHITE_COLOR;
        l.font = [UIFont systemFontOfSize:15];
        l.text = model.col1;
        [cell.contentView addSubview:l];
        return cell;
    }
    else if (model.cell_type==2){
        YZEPatientHeadTableViewCell2 *cell = [tableView dequeueReusableCellWithIdentifier:@"YZEPatientHeadTableViewCell2" forIndexPath:indexPath];
        cell.backgroundColor=[UIColor clearColor];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        
        [cell setData:model];
        return cell;
    }
    else if (model.cell_type==3){
        DailyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DailyTableViewCell" forIndexPath:indexPath];
        cell.backgroundColor=[UIColor clearColor];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        
        cell.col1label.text = model.col1;
        cell.col2label.text = model.col2;
        cell.col3label.text = model.col3;
        
        return cell;
    }
    else if (model.cell_type==4){
        YZEPatientHeadTableViewCell3 *cell = [tableView dequeueReusableCellWithIdentifier:@"YZEPatientHeadTableViewCell3" forIndexPath:indexPath];
        cell.backgroundColor=[UIColor clearColor];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        
        [cell setData:model];
        return cell;
    }
    return [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"none"];
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.01;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return [[UIView alloc]init];
}
@end
